package com.rabbitmq.service;

import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.rabbitmqConfig.RabbitMqConfig;

@Service("RabbitMqService")
public class RabbitMqServiceImpl implements RabbitMqService {

	@Autowired
	private AmqpTemplate amqpTemple;
	
	@Autowired
	private RabbitTemplate rabbitTemplate;
	
	@Override
	public String receiveMessage() {
		Object obj =amqpTemple.receiveAndConvert(RabbitMqConfig.DIRECT_QUEUE);
		
		return obj.toString();
	}
	@Override
	@RabbitListener(queues = {RabbitMqConfig.DIRECT_QUEUE})
	public void receiveMessage2(String message) {
		//Object obj =(String)amqpTemple.receiveAndConvert(RabbitMQConfig.DIRECT_QUEUE);
		
		System.out.println("receiveMessage2:"+message);
	}
	@Override
	@RabbitListener(queues = {RabbitMqConfig.DIRECT_QUEUE})
	public void receiveMessage3(String message) {
		//Object obj =(String)amqpTemple.receiveAndConvert(RabbitMQConfig.DIRECT_QUEUE);
		
		System.out.println("receiveMessage3:"+message);
	}
	@Override
	@RabbitListener(queues = {RabbitMqConfig.FANOUT_QUEUE1})
	public void receiveMessage4(String message) {
		//Object obj =(String)amqpTemple.receiveAndConvert(RabbitMQConfig.DIRECT_QUEUE);
		
		System.out.println("receiveMessage4:"+message);
	}
	@Override
	@RabbitListener(queues = {RabbitMqConfig.FANOUT_QUEUE2})
	public void receiveMessage5(String message) {
		//Object obj =(String)amqpTemple.receiveAndConvert(RabbitMQConfig.DIRECT_QUEUE);
		
		System.out.println("receiveMessage5:"+message);
	}
	@Override
	@RabbitListener(queues = {RabbitMqConfig.TOPIC_QUEUE1,RabbitMqConfig.TOPIC_QUEUE2})
	public void receiveTopicMessage(String message) {
		System.out.println("receiveTopicMessage:"+message);
		
	}
//	@Override
//	
//	public void receiveTopicMessage1(String message) {
//		rabbitTemplate.rec
//		
//	}
}
